export default {
  data() {
    return {
      contract: {},
      contractTemplate: [],

      isCreated: false
    }
  },
  // onLoad() {

  // },
  created() {
    this.m_setContract();
    this.isCreated = true
  },
  onShow() {
    if(this.isCreated) {
      this.m_setContract();
    }
  },
  methods: {
    m_setContract() {
      let globalData = getApp().globalData;
      this.contractTemplate.forEach((t) => {
        this.$set(this.contract, t.id, {
          disabled: !globalData.contract[t.id].read,
          check:
            globalData.contract[t.id].read && globalData.contract[t.id].check,
        });

        this.contract[t.id] = {
          disabled: !globalData.contract[t.id].read,
          check:
            globalData.contract[t.id].read && globalData.contract[t.id].check,
        };
      });
      console.log(this.contract);
    },
    m_handleCheckContract(value) {
      let id = value.target.id.slice(4)
      this.contract[id].check = getApp().globalData.contract[id].check =
        value.detail.value.length > 0;
    },
    m_lookContract(contract,readonly) {
      readonly = readonly === true ? '&readonly=1' : '&timer=1'
      uni.navigateTo({
        url: `/pages/my/contract?${contract.isPdf?'pdf':'id'}=${contract.id}&title=${contract.docTitle}${readonly}`,
      });
    },
    m_hasUnCheckContract() {
      // 测试环境跳过合同勾选
      if(getApp().globalData.baseUrl.indexOf('.com')===-1) {
        return
      }
      let contract = this.contractTemplate.find(
        (c) => !this.contract[c.id].check
      );
      if (contract) {
        let content = "请勾选《" + contract.docTitle + "》"
        if(this.$refs.popup) {
          this.$refs.popup.open(content);
        }else{
          uni.showModal({
            title: '提示',
            showCancel: false,
            content
          })
        }
        return true
      }
    }
  }
}